package com.molyfun.parents.activity.ask.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.utils.UIUtils;
import com.molyfun.parents.view.common.MfEditText;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 */
public class NewTagInputBarView extends LinearLayout implements View.OnClickListener{

    public static final int COMMENT_TYPE_REPLY = 1;//回复－和老师之间上面部分的内容
    public static final int COMMENT_TYPE_COMMENT = 2;//评论区域

    //状态根据当前话题是否是热门问题而定
    public int mCurrentCommentType = COMMENT_TYPE_COMMENT;

    protected LayoutInflater layoutInflater;

    private Context context;

    private String mTopicDetailId;
    private String mTargetCommentid;

    @InjectView(R.id.tag_input)
    MfEditText mTagInput;
    @InjectView(R.id.commit)
    TextView mCommit;

    public NewTagInputBarView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public NewTagInputBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public NewTagInputBarView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_new_tag_input_bar, this);
        ButterKnife.inject(this);
        mTagInput.setHint("请输入您要找的标签名");
        mCommit.setOnClickListener(this);
    }


    public void setNewTagAddCallback(NewTagAddCallback newTagAddCallback){
        this.mNewTagAddCallback = newTagAddCallback;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.commit:
                if(TextUtils.isEmpty(mTagInput.getText().toString().trim())){
                    UIUtils.showToast(getContext(), "请输入标签名");
                    return;
                }
                if(mNewTagAddCallback != null){
                    mNewTagAddCallback.onNewTagCommit(mTagInput.getText().toString().trim());
                    mTagInput.setText("");
                }
                break;
        }
    }

    private NewTagAddCallback mNewTagAddCallback;

    public static interface NewTagAddCallback{
        public void onNewTagCommit(String tag);
    }

}